import { observable, action } from 'mobx-miniprogram'
import { getstorage } from '@/miniprogram/utils/storage'
import { decodePublicKey } from '@/miniprogram/utils/security/security.js'
import Base64 from '@/miniprogram/utils/security/base64/base64'
let app = getApp()
export const userStore = observable({
   token: getstorage("token") || null,
   count: 11,
   temp: null,
   uusd: null,
   userInfo: {
      id: null,
      name: null,
      password: null,
      phone: null,
      levelId: null,
      nickName: null,
      email: null,
      header: null,
      genders: null,
      birth: null,
      city: null,
      job: null,
      sign: null,
      sourceType: null,
      integreat: null,
      growth: null,
      status: null,
      createTime: null,
      socialUid: null,
      accessToken: null,
      expoiresIn: null,
   },

   setToken: action(function (token) {
      this.token = token
   }),

   setUserInfo: action(function (userinfo) {
      this.userInfo = userinfo
   }),
   updateUserInfo: action(function () {
      this.temp = getstorage('temp'),
      this.uusd = getstorage('uusd')
   }),
   get userInfo() {
      return JSON.parse(decodePublicKey (this.uusd, this.temp));
   }
})
